package com.zjlanyun.erp.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zjlanyun.erp.R;
import com.zjlanyun.erp.model.ApproveDetailCaigouModel;
import com.zjlanyun.erp.utils.StringUtils;

public class ApproveDetailCaigouAdapter extends BaseAdapter {
	private ArrayList<ApproveDetailCaigouModel> mList;
	private LayoutInflater mInflater;
	private Context mContext;

	public final class ListItemView { // 自定义控件集合
		public TextView title;
		public TextView model;
		public TextView unit;
		public TextView quantity;
		public TextView unitprice;
		public TextView money;
	}

	public ApproveDetailCaigouAdapter(Context context,
			ArrayList<ApproveDetailCaigouModel> mList) {
		this.mInflater = LayoutInflater.from(context);
		this.mList = mList;
		this.mContext = context;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return mList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ListItemView listItemView = null;
		if (convertView == null) {
			listItemView = new ListItemView();
			convertView = mInflater.inflate(
					R.layout.approve_detail_caigou_item, null);
			listItemView.title = (TextView) convertView
					.findViewById(R.id.title);
			listItemView.model = (TextView) convertView
					.findViewById(R.id.model);
			listItemView.unit = (TextView) convertView.findViewById(R.id.unit);
			listItemView.quantity = (TextView) convertView
					.findViewById(R.id.quantity);
			listItemView.unitprice = (TextView) convertView
					.findViewById(R.id.unitprice);
			listItemView.money = (TextView) convertView
					.findViewById(R.id.money);
			convertView.setTag(listItemView);
		} else {
			listItemView = (ListItemView) convertView.getTag();
		}

		listItemView.title.setText(mList.get(position).getTitle());
		listItemView.model.setText(mList.get(position).getModel());
		listItemView.unit.setText(mList.get(position).getUnit());
		listItemView.quantity.setText(StringUtils.doubleToString(mList.get(
				position).getQuantity()));
		listItemView.unitprice.setText(StringUtils.doubleToString(mList.get(
				position).getUnitprice()));
		listItemView.money.setText(StringUtils.doubleToString(mList.get(
				position).getMoney()));

		return convertView;
	}
}
